//
//  CaseCell.m
//  FastDoctor
//
//  Created by 程建良 on 16/7/8.
//  Copyright © 2016年 sc. All rights reserved.
//

#import "CaseCell.h"
@interface CaseCell ()
@property (nonatomic,weak)UIImageView *caseImageView;
@property (nonatomic,weak)UILabel *illnessLabel;
@property (nonatomic,weak)UILabel *typeLabel;
@property (nonatomic,weak)UILabel *illnessName;
@property (nonatomic,weak)UILabel *typeDes;
@property (nonatomic,weak)UILabel *desLabel;
@property (nonatomic,weak)UILabel *timeLabel;
@property (nonatomic,weak)UIImageView *roundImageView;
@property (nonatomic,weak)UIView *lineView;
@end
@implementation CaseCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI{
    [self setupRoundImageView];
    [self setupLineView];
    self.timeLabel.text =@"";
    [self setupTimeLabel];
    self.caseImageView.image = nil;
    [self setupCaseImageView];
    self.illnessLabel.text = @"";
    [self setupIllnellLabel];
    self.typeLabel.text =@"";
    [self setupTypeLabel];
    self.illnessName.text = @"";
    [self setupIllnessName];
    self.typeDes.text = @"";
    [self setupTypeDes];
    self.desLabel.text = @"";
    [self setupDesLabel];
}
-(void)setupCaseImageView{
    UIImageView*imageView = [[UIImageView alloc]init];
    self.caseImageView = imageView;
    imageView.image = self.model.medicalImage;
    [self.contentView addSubview:imageView];
}
-(void)setupRoundImageView{
    UIImageView *imageView = [[UIImageView alloc]init];
    self.roundImageView = imageView;
    imageView.image = [UIImage imageNamed:@"illness_rb_img_sel.png"];
    [imageView sizeToFit];
    [self.contentView addSubview:imageView];
}
-(void)setupLineView{
    UIView *view = [[UIView alloc]init];
    self.lineView = view;
    view.backgroundColor = kThemeColor;
    [self.contentView addSubview:view];
}
-(void)setupIllnellLabel{
    UILabel *illNess = [[UILabel alloc]init];
    self.illnessLabel = illNess;
    self.illnessLabel.text = @"疾病类型:";
    self.illnessLabel.font = [UIFont systemFontOfSize:16];
    self.illnessLabel.textColor = [UIColor blackColor];
    [self.illnessLabel sizeToFit];
    [self.contentView addSubview:self.illnessLabel];
}
-(void)setupTimeLabel{
    UILabel *label = [[UILabel alloc]init];
    self.timeLabel = label;
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd hh:mm:ss";
    NSString *dateStr = [formatter stringFromDate:date];
    label.text = dateStr;
    label.font = [UIFont systemFontOfSize:16];
    label.textColor = [UIColor grayColor];
    [label sizeToFit];
    [self.contentView addSubview:label];
}
-(void)setupTypeLabel{
    UILabel *type = [[UILabel alloc]init];
    self.typeLabel = type;
    self.typeLabel.text = @"基本类型";
    self.typeLabel.font = [UIFont systemFontOfSize:16];
    self.typeLabel.textColor = [UIColor blackColor];
    [self.typeLabel sizeToFit];
    [self.contentView addSubview:self.typeLabel];
}
-(void)setupIllnessName{
    UILabel *label = [[UILabel alloc]init];
    self.illnessName = label;
    label.text = self.model.medicalName;
    label.font = [UIFont systemFontOfSize:16];
    label.textColor = [UIColor grayColor];
    [label sizeToFit];
    [self.contentView addSubview:label];
}
-(void)setupTypeDes{
    UILabel *label = [[UILabel alloc]init];
    self.typeDes = label;
    label.text = self.model.medicalDescrip;
    label.font = [UIFont systemFontOfSize:16];
    label.textColor = [UIColor grayColor];
    [label sizeToFit];
    [self.contentView addSubview:label];
}
-(void)setupDesLabel{
    UILabel *label = [[UILabel alloc]init];
    self.desLabel = label;
    label.text = self.model.medicalDetail;
    label.font = [UIFont systemFontOfSize:13];
    label.textColor = [UIColor grayColor];
    [label sizeToFit];
    label.numberOfLines = 0;
    [self.contentView addSubview:label];
}
-(void)layoutSubviews{
    [super layoutSubviews];
    [self.roundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(0);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.roundImageView.mas_bottom);
        make.left.offset(self.roundImageView.frame.size.width/2);
        make.width.mas_equalTo(1);
        make.bottom.offset(0);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(2);
        make.left.mas_equalTo(self.roundImageView.mas_right).offset(10);
    }];
    if (!self.model.medicalImage) {
        [self.illnessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.timeLabel.mas_left).offset(10);
        }];
        [self.illnessName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.illnessLabel.mas_right).offset(10);
        }];
        [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.illnessLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.illnessLabel.mas_left);
        }];
        [self.typeDes mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.illnessLabel.mas_bottom).offset(10);
             make.left.mas_equalTo(self.typeLabel.mas_right).offset(10);
        }];
        [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.typeLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.timeLabel.mas_left).offset(10);
        }];
    }else{
        [self.caseImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.timeLabel.mas_left);
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10);
            make.width.mas_equalTo(60);
            make.height.mas_equalTo(60);
        }];
        
        [self.illnessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.caseImageView.mas_right).offset(10);
        }];
        [self.illnessName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.illnessLabel.mas_right).offset(10);
        }];
        [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.illnessLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.illnessLabel.mas_left);
        }];
        [self.typeDes mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.illnessLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.typeLabel.mas_right).offset(10);
        }];
        [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.typeLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.caseImageView.mas_right).offset(10);
        }];
    }
}
-(void)setModel:(MeicalModel *)model{
    _model = model;
    [self setupUI];
    [self layoutSubviews];
}
@end
